﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;


namespace CloudApiServer.Controllers
{
    /// <summary>
    /// 山东进销存接口控制器
    /// </summary>
    [RoutePrefix("hsu/mihs")]
    public class FsiApiShandongJxcController : ApiController
    {
        /*接口*/
        /// <summary>
        /// 医保接口没找到的统一接口返回
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [HttpPost]
        public IHttpActionResult FsiNotFound(HttpRequestMessage request)
        {
            string url = request.RequestUri.ToString();
            string Method = request.Method.ToString();
            string Errnum = LogHelper.GetErrornumber();
            try
            {
                if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                {
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参为空！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
                else
                {
                    var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignIn>>(request.Content.ReadAsStringAsync().Result);
                    string infno = fsiRequest.infno;
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加！当前请求的接口号：{infno},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
            }
            catch (JsonReaderException)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参格式不正确！服务端无法正常反序列化！请检查入参是否为Json格式！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);

            }
            catch (Exception ex)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且服务端程序处理异常！请联系管理员排查！当前异常提示：{ex.Message},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);
            }
        }


        /*接口*/
        /// <summary>
        /// 医保接口没找到的统一接口返回
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("MihsServlet")]
        public IHttpActionResult MihsServletForGet(HttpRequestMessage request)
        {
            string url = request.RequestUri.ToString();
            string Method = request.Method.ToString();
            string Errnum = LogHelper.GetErrornumber();
            try
            {
                if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                {
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参为空！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
                else
                {
                    var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignIn>>(request.Content.ReadAsStringAsync().Result);
                    string infno = fsiRequest.infno;
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加！当前请求的接口号：{infno},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
            }
            catch (JsonReaderException)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参格式不正确！服务端无法正常反序列化！请检查入参是否为Json格式！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);

            }
            catch (Exception ex)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且服务端程序处理异常！请联系管理员排查！当前异常提示：{ex.Message},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);
            }
        }

        /// <summary>
        /// 山东地纬接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("MihsServlet")]
        [HttpPost]
        public async Task<IHttpActionResult> MihsServlet(HttpRequestMessage request)
        {
            try
            {
                if (FsiDatainfo.stateShandongJxcApi == false)
                {
                    throw new Exception("该接口已被控制台停用！请联系管理员！");
                }
                var fsiRequestabc = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignIn>>(request.Content.ReadAsStringAsync().Result);
                Console.WriteLine($"山东进销存入参:{request.Content.ReadAsStringAsync().Result}");
                string infno = fsiRequestabc.info;
                if (string.IsNullOrEmpty(infno))
                {
                    throw new Exception($"传入的参数有误!未获取到接口号infno,请检查入参！当前入参：{request.Content.ReadAsStringAsync().Result}");
                }
                string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
                switch (infno)
                {
                    case "9001":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignInShandong>>(request.Content.ReadAsStringAsync().Result);
                                string fixmedins_code = fsiRequest.fixmedins_code;
                                string fixmedins_name = fsiRequest.fixmedins_name;
                                string ip = fsiRequest.Input.data.ip;
                                string mac = fsiRequest.Input.data.mac;
                                string opter_no = fsiRequest.Input.data.opter_no;
                                if (string.IsNullOrEmpty(fixmedins_code) || string.IsNullOrEmpty(fixmedins_name) || string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(mac) || string.IsNullOrEmpty(opter_no))
                                {
                                    throw new Exception("参数校验失败：传入的机构代码|机构名称|IP|mac|操作员编号为空，请检查入参！当前入参：" + request.Content.ReadAsStringAsync().Result);
                                }
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                string signno = rnd.Next(1000000, 10000000).ToString();
                                string signtime = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "INSERT Into  fsi_signinout values(null,@fixmedins_code,@fixmedins_name,@ip,@mac,@opter_no,@sign_no,0,@signinTime,NULL)";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fixmedins_name);
                                    cmd.Parameters.AddWithValue("@ip", ip);
                                    cmd.Parameters.AddWithValue("@mac", mac);
                                    cmd.Parameters.AddWithValue("@opter_no", opter_no);
                                    cmd.Parameters.AddWithValue("@sign_no", signno);
                                    cmd.Parameters.AddWithValue("@signinTime", signtime);
                                    await cmd.ExecuteNonQueryAsync();

                                    var FsiHeader = new FsiHeader<outputsignInOutShandong>
                                    {
                                        output = new outputsignInOutShandong
                                        {
                                            result = new signInOut
                                            {
                                                sign_no = signno,
                                                sign_time = signtime
                                            }
                                        },
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid = $"430000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"

                                    };
                                    return Json(FsiHeader);
                                }

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}" 
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }

                            }
                        }
                    case "9002":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignOutShandong>>(request.Content.ReadAsStringAsync().Result);
                                string fixmedins_code = fsiRequest.fixmedins_code;
                                string opter_no = fsiRequest.Input.data.opter_no;
                                string sign_no = fsiRequest.Input.data.sign_no;
                                if (string.IsNullOrEmpty(fixmedins_code) || string.IsNullOrEmpty(sign_no) || string.IsNullOrEmpty(opter_no))
                                {
                                    throw new Exception("参数校验失败：传入的机构代码|签到号|操作员编号为空，请检查入参！当前入参：" + request.Content.ReadAsStringAsync().Result);
                                }
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                string siginoutTime = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "select * from fsi_signinout where fixmedins_code=@fixmedins_code and opter_no=@opter_no and sign_no= @sign_no and state=0 ";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fixmedins_code);
                                    cmd.Parameters.AddWithValue("@opter_no", opter_no);
                                    cmd.Parameters.AddWithValue("@sign_no", sign_no);
                                    using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                                    {
                                        DataTable dt = new DataTable();
                                        dt.Load(reader);
                                        if (dt.Rows.Count < 1)
                                        {
                                            throw new Exception($"查询签到表失败：根据传入的机构代码、操作员编号和签到编号未找到签到信息或已是签退状态！当前获取到了{dt.Rows.Count}条有效的签到记录。当前入参：" + request.Content.ReadAsStringAsync().Result);
                                        }
                                        else
                                        {
                                            cmd.Parameters.Clear();
                                            cmd.CommandText = "update  fsi_signinout set state=1,siginoutTime=@siginoutTime where fixmedins_code=@fixmedins_code and opter_no=@opter_no and sign_no= @sign_no and state=0 ";
                                            cmd.Parameters.AddWithValue("@fixmedins_code", fixmedins_code);
                                            cmd.Parameters.AddWithValue("@opter_no", opter_no);
                                            cmd.Parameters.AddWithValue("@sign_no", sign_no);
                                            cmd.Parameters.AddWithValue("@siginoutTime", siginoutTime);
                                            await cmd.ExecuteNonQueryAsync();
                                            var FsiHeader = new FsiHeader<outputsignInOut>
                                            {
                                                output = new outputsignInOut
                                                {
                                                    signinoutb = new signInOut
                                                    {
                                                        sign_time = siginoutTime
                                                    }
                                                },
                                                infcode = 0,
                                                warn_msg = null,
                                                cainfo = null,
                                                err_msg = "success",
                                                refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                                signtype = null,
                                                respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                                inf_refmsgid = $"430000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                            };
                                            return Json(FsiHeader);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}" 
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3501":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsUpload>>(request.Content.ReadAsStringAsync().Result);
                                if (FsiDatainfo.stateFsiApi == false)
                                {
                                    throw new Exception("该接口已被控制台停用！请联系管理员！");
                                }
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "INSERT INTO fsi_goodsupload  VALUES ( null,@fixmedins_code,@fixmedins_name, @med_list_codg,@fixmedins_hilist_id, @fixmedins_hilist_name, " +
                                            "@rx_flag, @invdate, @inv_cnt, @manu_lotnum, @fixmedins_bchno, @manu_date, @expy_end, @memo, 0, @InputJson, @create_time,@update_time)";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.invinfo.med_list_codg);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.invinfo.fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name", fsiRequest.Input.invinfo.fixmedins_hilist_name);
                                    cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.invinfo.rx_flag);
                                    cmd.Parameters.AddWithValue("@invdate", fsiRequest.Input.invinfo.invdate);
                                    cmd.Parameters.AddWithValue("@inv_cnt", fsiRequest.Input.invinfo.inv_cnt);
                                    cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.invinfo.manu_lotnum);
                                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.invinfo.fixmedins_bchno);
                                    cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.invinfo.manu_date);
                                    cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.invinfo.expy_end);
                                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.invinfo.memo);
                                    cmd.Parameters.AddWithValue("@InputJson", request.Content.ReadAsStringAsync().Result);
                                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3502":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsUpdate>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "INSERT INTO fsi_goodsupdate  VALUES ( null,@fixmedins_code,@fixmedins_name, @med_list_codg,@inv_chg_type,@fixmedins_hilist_id, @fixmedins_hilist_name, " +
                                            "@fixmedins_bchno, @pric, @cnt, @rx_flag, @inv_chg_time, @inv_chg_opter_name, @memo, @trdn_flag, 0, @InputJson, @create_time,@update_time)";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.invinfo.med_list_codg);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.invinfo.fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name", fsiRequest.Input.invinfo.fixmedins_hilist_name);
                                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.invinfo.fixmedins_bchno);
                                    cmd.Parameters.AddWithValue("@inv_chg_type", fsiRequest.Input.invinfo.inv_chg_type);
                                    cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.invinfo.rx_flag);
                                    cmd.Parameters.AddWithValue("@pric", fsiRequest.Input.invinfo.pric);
                                    cmd.Parameters.AddWithValue("@cnt", fsiRequest.Input.invinfo.cnt);
                                    cmd.Parameters.AddWithValue("@inv_chg_time", fsiRequest.Input.invinfo.inv_chg_time);
                                    cmd.Parameters.AddWithValue("@inv_chg_opter_name", fsiRequest.Input.invinfo.inv_chg_opter_name);
                                    cmd.Parameters.AddWithValue("@trdn_flag", fsiRequest.Input.invinfo.trdn_flag);
                                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.invinfo.memo);
                                    cmd.Parameters.AddWithValue("@InputJson", request.Content.ReadAsStringAsync().Result);
                                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3503":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsBuy>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "INSERT INTO fsi_goodsbuy  VALUES ( null,@fixmedins_code,@fixmedins_name,@med_list_codg,@fixmedins_hilist_id," +
                                        " @fixmedins_hilist_name,@dynt_no,@fixmedins_bchno,@spler_name,@spler_pmtno," +
                                        " @manu_lotnum,@prodentp_name, @aprvno, @manu_date,@expy_end," +
                                        "@finl_trns_pric,@purc_retn_cnt,@purc_invo_codg,@purc_invo_no, @rx_flag," +
                                    " @purc_retn_stoin_time, @purc_retn_opter_name, @prod_geay_flag,@memo,0,0," +
                                    " @InputJson, @create_time,@update_time)";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.purcinfo.med_list_codg);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.purcinfo.fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name", fsiRequest.Input.purcinfo.fixmedins_hilist_name);

                                    cmd.Parameters.AddWithValue("@dynt_no", fsiRequest.Input.purcinfo.dynt_no);
                                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.purcinfo.fixmedins_bchno);
                                    cmd.Parameters.AddWithValue("@spler_name", fsiRequest.Input.purcinfo.spler_name);
                                    cmd.Parameters.AddWithValue("@spler_pmtno", fsiRequest.Input.purcinfo.spler_pmtno);
                                    cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.purcinfo.manu_lotnum);

                                    cmd.Parameters.AddWithValue("@prodentp_name", fsiRequest.Input.purcinfo.prodentp_name);
                                    cmd.Parameters.AddWithValue("@aprvno", fsiRequest.Input.purcinfo.aprvno);
                                    cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.purcinfo.manu_date);
                                    cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.purcinfo.expy_end);
                                    cmd.Parameters.AddWithValue("@finl_trns_pric", fsiRequest.Input.purcinfo.finl_trns_pric);

                                    cmd.Parameters.AddWithValue("@purc_retn_cnt", fsiRequest.Input.purcinfo.purc_retn_cnt);
                                    cmd.Parameters.AddWithValue("@purc_invo_codg", fsiRequest.Input.purcinfo.purc_invo_codg);
                                    cmd.Parameters.AddWithValue("@purc_invo_no", fsiRequest.Input.purcinfo.purc_invo_no);
                                    cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.purcinfo.rx_flag);
                                    cmd.Parameters.AddWithValue("@purc_retn_stoin_time", fsiRequest.Input.purcinfo.purc_retn_stoin_time);

                                    cmd.Parameters.AddWithValue("@purc_retn_opter_name", fsiRequest.Input.purcinfo.purc_retn_opter_name);
                                    cmd.Parameters.AddWithValue("@prod_geay_flag", fsiRequest.Input.purcinfo.prod_geay_flag);
                                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.purcinfo.memo);
                                    cmd.Parameters.AddWithValue("@InputJson", request.Content.ReadAsStringAsync().Result);
                                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3504":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsBuy>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "select * from fsi_goodsbuy  where fixmedins_code =@fixmedins_code and med_list_codg =@med_list_codg and fixmedins_hilist_id =@fixmedins_hilist_id and fixmedins_bchno=@fixmedins_bchno and state =0 and datatype=0";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.purcinfo.med_list_codg);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.purcinfo.fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.purcinfo.fixmedins_bchno);
                                    using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                                    {
                                        cmd.Parameters.Clear();
                                        DataTable dt = new DataTable();
                                        dt.Load(reader);
                                        if (dt.Rows.Count < 1)
                                        {
                                            throw new Exception($"查询采购上传记录表失败！根据传入的机构代码：{fsiRequest.fixmedins_code} 医保目录编码：{fsiRequest.Input.purcinfo.med_list_codg} 医疗机构内部编码：{fsiRequest.Input.purcinfo.fixmedins_hilist_id} 批次号：{fsiRequest.Input.purcinfo.fixmedins_bchno}查询到的采购上传记录总数为：{dt.Rows.Count}");
                                        }
                                        else
                                        {
                                            cmd.CommandText = "INSERT INTO fsi_goodsbuy  VALUES ( null,@fixmedins_code,@fixmedins_name,@med_list_codg,@fixmedins_hilist_id," +
                                            " @fixmedins_hilist_name,@dynt_no,@fixmedins_bchno,@spler_name,@spler_pmtno," +
                                            " @manu_lotnum,@prodentp_name, @aprvno, @manu_date,@expy_end," +
                                            "@finl_trns_pric,@purc_retn_cnt,@purc_invo_codg,@purc_invo_no, @rx_flag," +
                                            " @purc_retn_stoin_time, @purc_retn_opter_name, @prod_geay_flag,@memo, 1,0," +
                                            " @InputJson, @create_time,@update_time)";
                                            cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                            cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                            cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.purcinfo.med_list_codg);
                                            cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.purcinfo.fixmedins_hilist_id);
                                            cmd.Parameters.AddWithValue("@fixmedins_hilist_name", fsiRequest.Input.purcinfo.fixmedins_hilist_name);

                                            cmd.Parameters.AddWithValue("@dynt_no", fsiRequest.Input.purcinfo.dynt_no);
                                            cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.purcinfo.fixmedins_bchno);
                                            cmd.Parameters.AddWithValue("@spler_name", fsiRequest.Input.purcinfo.spler_name);
                                            cmd.Parameters.AddWithValue("@spler_pmtno", fsiRequest.Input.purcinfo.spler_pmtno);
                                            cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.purcinfo.manu_lotnum);

                                            cmd.Parameters.AddWithValue("@prodentp_name", fsiRequest.Input.purcinfo.prodentp_name);
                                            cmd.Parameters.AddWithValue("@aprvno", fsiRequest.Input.purcinfo.aprvno);
                                            cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.purcinfo.manu_date);
                                            cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.purcinfo.expy_end);
                                            cmd.Parameters.AddWithValue("@finl_trns_pric", fsiRequest.Input.purcinfo.finl_trns_pric);

                                            cmd.Parameters.AddWithValue("@purc_retn_cnt", fsiRequest.Input.purcinfo.purc_retn_cnt);
                                            cmd.Parameters.AddWithValue("@purc_invo_codg", fsiRequest.Input.purcinfo.purc_invo_codg);
                                            cmd.Parameters.AddWithValue("@purc_invo_no", fsiRequest.Input.purcinfo.purc_invo_no);
                                            cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.purcinfo.rx_flag);
                                            cmd.Parameters.AddWithValue("@purc_retn_stoin_time", fsiRequest.Input.purcinfo.purc_retn_stoin_time);

                                            cmd.Parameters.AddWithValue("@purc_retn_opter_name", fsiRequest.Input.purcinfo.purc_retn_opter_name);
                                            cmd.Parameters.AddWithValue("@prod_geay_flag", fsiRequest.Input.purcinfo.prod_geay_flag);
                                            cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.purcinfo.memo);
                                            cmd.Parameters.AddWithValue("@InputJson", request.Content.ReadAsStringAsync().Result);
                                            cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                            cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                            await cmd.ExecuteNonQueryAsync();
                                            cmd.Parameters.Clear();
                                        }
                                    }

                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3505":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsSell>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "INSERT INTO fsi_goodsSell VALUES ( " +
                                        " null,@fixmedins_code,@fixmedins_name,@med_list_codg,@fixmedins_hilist_id," +
                                        " @fixmedins_hilist_name,@fixmedins_bchno,@prsc_dr_cert_type,@prsc_dr_certno,@prsc_dr_name," +
                                        " @phar_cert_type,@phar_certno, @phar_name, @phar_prac_cert_no,@hi_feesetl_type," +
                                        " @setl_id,@mdtrt_sn,@psn_no,@psn_cert_type, @certno," +
                                        " @psn_name, @manu_lotnum, @manu_date,@expy_end,@rx_flag," +
                                        " @trdn_flag, @finl_trns_pric, @rxno,@rx_circ_flag,@rtal_docno," +
                                        " @stoout_no, @bchno, @drug_trac_codg,@drug_prod_barc,@shelf_posi," +
                                        " @sel_retn_cnt, @sel_retn_time, @sel_retn_opter_name,@memo,@mdtrt_setl_type," +
                                        " 0,0,@InputJson, @create_time,@update_time)";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.selinfo.med_list_codg);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.selinfo.fixmedins_hilist_id);

                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name", fsiRequest.Input.selinfo.fixmedins_hilist_name);
                                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.selinfo.fixmedins_bchno);
                                    cmd.Parameters.AddWithValue("@prsc_dr_cert_type", fsiRequest.Input.selinfo.prsc_dr_cert_type);
                                    cmd.Parameters.AddWithValue("@prsc_dr_certno", fsiRequest.Input.selinfo.prsc_dr_certno);
                                    cmd.Parameters.AddWithValue("@prsc_dr_name", fsiRequest.Input.selinfo.prsc_dr_name);

                                    cmd.Parameters.AddWithValue("@phar_cert_type", fsiRequest.Input.selinfo.phar_cert_type);
                                    cmd.Parameters.AddWithValue("@phar_certno", fsiRequest.Input.selinfo.phar_certno);
                                    cmd.Parameters.AddWithValue("@phar_name", fsiRequest.Input.selinfo.phar_name);
                                    cmd.Parameters.AddWithValue("@phar_prac_cert_no", fsiRequest.Input.selinfo.phar_prac_cert_no);
                                    cmd.Parameters.AddWithValue("@hi_feesetl_type", fsiRequest.Input.selinfo.hi_feesetl_type);

                                    cmd.Parameters.AddWithValue("@setl_id", fsiRequest.Input.selinfo.setl_id);
                                    cmd.Parameters.AddWithValue("@mdtrt_sn", fsiRequest.Input.selinfo.mdtrt_sn);
                                    cmd.Parameters.AddWithValue("@psn_no", fsiRequest.Input.selinfo.psn_no);
                                    cmd.Parameters.AddWithValue("@psn_cert_type", fsiRequest.Input.selinfo.psn_cert_type);
                                    cmd.Parameters.AddWithValue("@certno", fsiRequest.Input.selinfo.certno);

                                    cmd.Parameters.AddWithValue("@psn_name", fsiRequest.Input.selinfo.psn_name);
                                    cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.selinfo.manu_lotnum);
                                    cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.selinfo.manu_date);
                                    cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.selinfo.expy_end);
                                    cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.selinfo.rx_flag);

                                    cmd.Parameters.AddWithValue("@trdn_flag", fsiRequest.Input.selinfo.trdn_flag);
                                    cmd.Parameters.AddWithValue("@finl_trns_pric", fsiRequest.Input.selinfo.finl_trns_pric);
                                    cmd.Parameters.AddWithValue("@rxno", fsiRequest.Input.selinfo.rxno);
                                    cmd.Parameters.AddWithValue("@rx_circ_flag", fsiRequest.Input.selinfo.rx_circ_flag);
                                    cmd.Parameters.AddWithValue("@rtal_docno", fsiRequest.Input.selinfo.rtal_docno);

                                    cmd.Parameters.AddWithValue("@stoout_no", fsiRequest.Input.selinfo.stoout_no);
                                    cmd.Parameters.AddWithValue("@bchno", fsiRequest.Input.selinfo.bchno);
                                    cmd.Parameters.AddWithValue("@drug_trac_codg", fsiRequest.Input.selinfo.drug_trac_codg);
                                    cmd.Parameters.AddWithValue("@drug_prod_barc", fsiRequest.Input.selinfo.drug_prod_barc);
                                    cmd.Parameters.AddWithValue("@shelf_posi", fsiRequest.Input.selinfo.shelf_posi);

                                    cmd.Parameters.AddWithValue("@sel_retn_cnt", fsiRequest.Input.selinfo.sel_retn_cnt);
                                    cmd.Parameters.AddWithValue("@sel_retn_time", fsiRequest.Input.selinfo.sel_retn_time);
                                    cmd.Parameters.AddWithValue("@sel_retn_opter_name", fsiRequest.Input.selinfo.sel_retn_opter_name);
                                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.selinfo.memo);
                                    cmd.Parameters.AddWithValue("@mdtrt_setl_type", fsiRequest.Input.selinfo.mdtrt_setl_type);


                                    cmd.Parameters.AddWithValue("@InputJson", request.Content.ReadAsStringAsync().Result);
                                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3506":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsSellList>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "select * from fsi_goodsSell  where fixmedins_code =@fixmedins_code and med_list_codg =@med_list_codg and fixmedins_hilist_id =@fixmedins_hilist_id and fixmedins_bchno=@fixmedins_bchno and state =0 and datatype=0";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.selinfo[0].med_list_codg);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.selinfo[0].fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.selinfo[0].fixmedins_bchno);
                                    using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                                    {
                                        cmd.Parameters.Clear();
                                        DataTable dt = new DataTable();
                                        dt.Load(reader);
                                        if (dt.Rows.Count < 1)
                                        {
                                            throw new Exception($"查询销售上传记录表失败！根据传入的机构代码：{fsiRequest.fixmedins_code} 医保目录编码：{fsiRequest.Input.selinfo[0].med_list_codg} 医疗机构内部编码：{fsiRequest.Input.selinfo[0].fixmedins_hilist_id} 批次号：{fsiRequest.Input.selinfo[0].fixmedins_bchno}查询到的销售上传记录总数为：{dt.Rows.Count}");
                                        }
                                        else
                                        {
                                            cmd.CommandText = "INSERT INTO fsi_goodsSell VALUES ( " +
                                            " null,@fixmedins_code,@fixmedins_name,@med_list_codg,@fixmedins_hilist_id," +
                                            " @fixmedins_hilist_name,@fixmedins_bchno,@prsc_dr_cert_type,@prsc_dr_certno,@prsc_dr_name," +
                                            " @phar_cert_type,@phar_certno, @phar_name, @phar_prac_cert_no,@hi_feesetl_type," +
                                            " @setl_id,@mdtrt_sn,@psn_no,@psn_cert_type, @certno," +
                                            " @psn_name, @manu_lotnum, @manu_date,@expy_end,@rx_flag," +
                                            " @trdn_flag, @finl_trns_pric, @rxno,@rx_circ_flag,@rtal_docno," +
                                            " @stoout_no, @bchno, @drug_trac_codg,@drug_prod_barc,@shelf_posi," +
                                            " @sel_retn_cnt, @sel_retn_time, @sel_retn_opter_name,@memo,@mdtrt_setl_type," +
                                            " 1,0,@InputJson, @create_time,@update_time)";
                                            cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                            cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                            cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.selinfo[0].med_list_codg);
                                            cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.selinfo[0].fixmedins_hilist_id);

                                            cmd.Parameters.AddWithValue("@fixmedins_hilist_name", fsiRequest.Input.selinfo[0].fixmedins_hilist_name);
                                            cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.selinfo[0].fixmedins_bchno);
                                            cmd.Parameters.AddWithValue("@prsc_dr_cert_type", fsiRequest.Input.selinfo[0].prsc_dr_cert_type);
                                            cmd.Parameters.AddWithValue("@prsc_dr_certno", fsiRequest.Input.selinfo[0].prsc_dr_certno);
                                            cmd.Parameters.AddWithValue("@prsc_dr_name", fsiRequest.Input.selinfo[0].prsc_dr_name);

                                            cmd.Parameters.AddWithValue("@phar_cert_type", fsiRequest.Input.selinfo[0].phar_cert_type);
                                            cmd.Parameters.AddWithValue("@phar_certno", fsiRequest.Input.selinfo[0].phar_certno);
                                            cmd.Parameters.AddWithValue("@phar_name", fsiRequest.Input.selinfo[0].phar_name);
                                            cmd.Parameters.AddWithValue("@phar_prac_cert_no", fsiRequest.Input.selinfo[0].phar_prac_cert_no);
                                            cmd.Parameters.AddWithValue("@hi_feesetl_type", fsiRequest.Input.selinfo[0].hi_feesetl_type);

                                            cmd.Parameters.AddWithValue("@setl_id", fsiRequest.Input.selinfo[0].setl_id);
                                            cmd.Parameters.AddWithValue("@mdtrt_sn", fsiRequest.Input.selinfo[0].mdtrt_sn);
                                            cmd.Parameters.AddWithValue("@psn_no", fsiRequest.Input.selinfo[0].psn_no);
                                            cmd.Parameters.AddWithValue("@psn_cert_type", fsiRequest.Input.selinfo[0].psn_cert_type);
                                            cmd.Parameters.AddWithValue("@certno", fsiRequest.Input.selinfo[0].certno);

                                            cmd.Parameters.AddWithValue("@psn_name", fsiRequest.Input.selinfo[0].psn_name);
                                            cmd.Parameters.AddWithValue("@manu_lotnum", fsiRequest.Input.selinfo[0].manu_lotnum);
                                            cmd.Parameters.AddWithValue("@manu_date", fsiRequest.Input.selinfo[0].manu_date);
                                            cmd.Parameters.AddWithValue("@expy_end", fsiRequest.Input.selinfo[0].expy_end);
                                            cmd.Parameters.AddWithValue("@rx_flag", fsiRequest.Input.selinfo[0].rx_flag);

                                            cmd.Parameters.AddWithValue("@trdn_flag", fsiRequest.Input.selinfo[0].trdn_flag);
                                            cmd.Parameters.AddWithValue("@finl_trns_pric", fsiRequest.Input.selinfo[0].finl_trns_pric);
                                            cmd.Parameters.AddWithValue("@rxno", fsiRequest.Input.selinfo[0].rxno);
                                            cmd.Parameters.AddWithValue("@rx_circ_flag", fsiRequest.Input.selinfo[0].rx_circ_flag);
                                            cmd.Parameters.AddWithValue("@rtal_docno", fsiRequest.Input.selinfo[0].rtal_docno);

                                            cmd.Parameters.AddWithValue("@stoout_no", fsiRequest.Input.selinfo[0].stoout_no);
                                            cmd.Parameters.AddWithValue("@bchno", fsiRequest.Input.selinfo[0].bchno);
                                            cmd.Parameters.AddWithValue("@drug_trac_codg", fsiRequest.Input.selinfo[0].drug_trac_codg);
                                            cmd.Parameters.AddWithValue("@drug_prod_barc", fsiRequest.Input.selinfo[0].drug_prod_barc);
                                            cmd.Parameters.AddWithValue("@shelf_posi", fsiRequest.Input.selinfo[0].shelf_posi);

                                            cmd.Parameters.AddWithValue("@sel_retn_cnt", fsiRequest.Input.selinfo[0].sel_retn_cnt);
                                            cmd.Parameters.AddWithValue("@sel_retn_time", fsiRequest.Input.selinfo[0].sel_retn_time);
                                            cmd.Parameters.AddWithValue("@sel_retn_opter_name", fsiRequest.Input.selinfo[0].sel_retn_opter_name);
                                            cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.selinfo[0].memo);
                                            cmd.Parameters.AddWithValue("@mdtrt_setl_type", fsiRequest.Input.selinfo[0].mdtrt_setl_type);


                                            cmd.Parameters.AddWithValue("@InputJson", request.Content.ReadAsStringAsync().Result);
                                            cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                            cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                            await cmd.ExecuteNonQueryAsync();
                                            cmd.Parameters.Clear();
                                        }
                                    }

                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3507":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsInfoDelete>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                string fixmedins_code = fsiRequest.fixmedins_code;
                                string fixmedins_bchno = fsiRequest.Input.data.fixmedins_bchno;
                                string inv_data_type = fsiRequest.Input.data.inv_data_type;

                                string tablename = string.Empty;
                                switch (inv_data_type)
                                {
                                    case "1":
                                        tablename = "fsi_goodsupload";
                                        break;
                                    case "2":
                                        tablename = "fsi_goodsupdate";
                                        break;
                                    case "3":
                                        tablename = "fsi_goodsbuy";
                                        break;
                                    case "4":
                                        tablename = "fsi_goodssell";
                                        break;
                                    default:
                                        throw new Exception($"校验进销存数据类型失败：进销存数据类型{inv_data_type}未被定义！");
                                }

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = $"select * from {tablename}  where fixmedins_code =@fixmedins_code and fixmedins_bchno=@fixmedins_bchno and state =0";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.data.fixmedins_bchno);
                                    using (MySqlDataReader reader = (MySqlDataReader)await cmd.ExecuteReaderAsync())
                                    {
                                        cmd.Parameters.Clear();
                                        DataTable dt = new DataTable();
                                        dt.Load(reader);
                                        if (dt.Rows.Count < 1)
                                        {
                                            throw new Exception($"查询{tablename}记录表失败！根据传入的机构代码：{fixmedins_code} 上传类型：{inv_data_type}  批次号：{fixmedins_bchno} 查询到的记录总数为：{dt.Rows.Count}");
                                        }
                                        else
                                        {
                                            cmd.CommandText = $"update  {tablename} set state=1,update_time= @update_time where fixmedins_code =@fixmedins_code and fixmedins_bchno=@fixmedins_bchno and state =0 ";
                                            cmd.Parameters.AddWithValue("@tablename", tablename);
                                            cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                            cmd.Parameters.AddWithValue("@fixmedins_bchno", fsiRequest.Input.data.fixmedins_bchno);
                                            cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                            await cmd.ExecuteNonQueryAsync();
                                            cmd.Parameters.Clear();
                                        }
                                    }

                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3568":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodStocks>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "INSERT INTO `data`.`fsi_goodsstocks` (`fixmedins_code`, `fixmedins_name`, `prod_type`, " +
                                        "`med_list_codg`, `fixmedins_hilist_id`, `fixmedins_hilist_name`, `inv_cnt`, `pric`, `stockstatus`, `memo`, " +
                                        "`vali_flag`, `state`, `InputJson`, `create_time`, `update_time`) VALUES (@fixmedins_code, @fixmedins_name, @prod_type, " +
                                        "@med_list_codg, @fixmedins_hilist_id, @fixmedins_hilist_name," +
                                        " @inv_cnt, @pric,@stockstatus, @memo, @vali_flag,@state, @InputJson, @create_time, @create_time)";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                    cmd.Parameters.AddWithValue("@prod_type", fsiRequest.Input.invinfo.prod_type);
                                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.invinfo.med_list_codg);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.invinfo.fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name", fsiRequest.Input.invinfo.fixmedins_hilist_name);
                                    cmd.Parameters.AddWithValue("@inv_cnt", fsiRequest.Input.invinfo.inv_cnt);
                                    cmd.Parameters.AddWithValue("@pric", fsiRequest.Input.invinfo.pric);
                                    cmd.Parameters.AddWithValue("@stockstatus", fsiRequest.Input.invinfo.stockstatus);
                                    cmd.Parameters.AddWithValue("@vali_flag", fsiRequest.Input.invinfo.vali_flag);
                                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.invinfo.memo);

                                    cmd.Parameters.AddWithValue("@state", 0);
                                    cmd.Parameters.AddWithValue("@InputJson", request.Content.ReadAsStringAsync().Result);
                                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3569":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsInformationInfo>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "INSERT INTO `data`.`fsi_goodsinformationinfo` ( `fixmedins_code`, `fixmedins_name`, `fixmedins_hilist_id`, `entp_code`, " +
                                        "`entp_name`, `entp_type`, `busilicperson`, `manager`, `telephone`, `regaddress`, `address`, `province`, `city`, `county`, `city_flag`, " +
                                        "`openingbank`, `accountnumber`, `taxcode`, `isreceipttype`, `uscc`, `busilicissue`, `busilicexp`, `busilicissuedate`, `busiliccheckdate`," +
                                        " `businessscope`, `qaexpdate`, `qcmanager`, `licence`, `licenceexp`, `licenceissue`, `licencescope`, `licenceissuedate`, `InputJson`, `create_time`, " +
                                        "`update_time`) VALUES (@fixmedins_code, @fixmedins_name, @fixmedins_hilist_id, @entp_code, @entp_name, @entp_type,@busilicperson, @manager, " +
                                        "@telephone, @regaddress, @address, @province, @city, @county, @city_flag," +
                                        " @openingbank, @accountnumber, @taxcode, @isreceipttype, @uscc,@busilicissue, @busilicexp, @busilicissuedate, @busiliccheckdate, " +
                                        "@businessscope, @qaexpdate, @qcmanager, @licence, @licenceexp, @licenceissue, @licencescope, @licenceissuedate, @InputJson, @create_time, @update_time)";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.entpbaseinfo.fixmedins_hilist_id);

                                    cmd.Parameters.AddWithValue("@entp_code", fsiRequest.Input.entpbaseinfo.entp_code);
                                    cmd.Parameters.AddWithValue("@entp_name", fsiRequest.Input.entpbaseinfo.entp_name);
                                    cmd.Parameters.AddWithValue("@entp_type", fsiRequest.Input.entpbaseinfo.entp_type);
                                    cmd.Parameters.AddWithValue("@busilicperson", fsiRequest.Input.entpbaseinfo.busilicperson);
                                    cmd.Parameters.AddWithValue("@manager", fsiRequest.Input.entpbaseinfo.manager); 
                                    cmd.Parameters.AddWithValue("@telephone", fsiRequest.Input.entpbaseinfo.telephone);
                                    cmd.Parameters.AddWithValue("@regaddress", fsiRequest.Input.entpbaseinfo.regaddress);
                                    cmd.Parameters.AddWithValue("@address", fsiRequest.Input.entpbaseinfo.address);
                                    cmd.Parameters.AddWithValue("@province", fsiRequest.Input.entpbaseinfo.province);
                                    cmd.Parameters.AddWithValue("@city", fsiRequest.Input.entpbaseinfo.city);
                                    cmd.Parameters.AddWithValue("@county", fsiRequest.Input.entpbaseinfo.county);
                                    cmd.Parameters.AddWithValue("@city_flag", fsiRequest.Input.entpbaseinfo.city_flag);
                                    cmd.Parameters.AddWithValue("@openingbank", fsiRequest.Input.entpbaseinfo.openingbank);
                                    cmd.Parameters.AddWithValue("@accountnumber", fsiRequest.Input.entpbaseinfo.accountnumber);
                                    cmd.Parameters.AddWithValue("@taxcode", fsiRequest.Input.entpbaseinfo.taxcode);
                                    cmd.Parameters.AddWithValue("@isreceipttype", fsiRequest.Input.entpbaseinfo.isreceipttype);
                                    cmd.Parameters.AddWithValue("@uscc", fsiRequest.Input.entpbaseinfo.uscc);
                                    cmd.Parameters.AddWithValue("@busilicissue", fsiRequest.Input.entpbaseinfo.busilicissue);
                                    cmd.Parameters.AddWithValue("@busilicexp", fsiRequest.Input.entpbaseinfo.busilicexp);
                                    cmd.Parameters.AddWithValue("@busilicissuedate", fsiRequest.Input.entpbaseinfo.busilicissuedate);
                                    cmd.Parameters.AddWithValue("@busiliccheckdate", fsiRequest.Input.entpbaseinfo.busiliccheckdate);
                                    cmd.Parameters.AddWithValue("@businessscope", fsiRequest.Input.entpbaseinfo.businessscope);
                                    cmd.Parameters.AddWithValue("@qaexpdate", fsiRequest.Input.entpbaseinfo.qaexpdate);
                                    cmd.Parameters.AddWithValue("@qcmanager", fsiRequest.Input.entpbaseinfo.qcmanager);
                                    cmd.Parameters.AddWithValue("@licence", fsiRequest.Input.entpbaseinfo.licence);
                                    cmd.Parameters.AddWithValue("@licenceexp", fsiRequest.Input.entpbaseinfo.licenceexp);
                                    cmd.Parameters.AddWithValue("@licenceissue", fsiRequest.Input.entpbaseinfo.licenceissue);
                                    cmd.Parameters.AddWithValue("@licencescope", fsiRequest.Input.entpbaseinfo.licencescope);
                                    cmd.Parameters.AddWithValue("@licenceissuedate", fsiRequest.Input.entpbaseinfo.licenceissuedate);
                                    cmd.Parameters.AddWithValue("@InputJson", request.Content.ReadAsStringAsync().Result);
                                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    case "3599":
                        using (MySqlConnection conn = new MySqlConnection(connectionString))
                        {
                            try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsSellTracInfo>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                long dtunix = PublicMethod.ConvertToUnixTimestampMillis(dateTime);

                                await conn.OpenAsync();
                                using (MySqlCommand cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText = "INSERT INTO `data`.`fsi_goodsselltracinfo` ( `fixmedins_code`, `fixmedins_name`, `setl_id`, `setl_flag`, " +
                                        "`init_setl_id`, `fixmedins_hilist_id`, `fixmedins_hilist_name`, `med_type`, `mdtrt_sn`, `psn_no`, `psn_cert_type`, `certno`," +
                                        " `psn_name`, `bkkp_sn`, `trdn_flag`, `Setl_pric`, `sel_cnt`, `setl_time`, `prcunt`, `memo`, `med_list_codg`, `state`, `InputJson`," +
                                        " `create_time`, `update_time`) VALUES ( @fixmedins_code, @fixmedins_name, @setl_id, @setl_flag, @init_setl_id,@fixmedins_hilist_id, @fixmedins_hilist_name," +
                                        " @med_type, @mdtrt_sn, @psn_no, @psn_cert_type, @certno, @psn_name, @bkkp_sn,@trdn_flag, @Setl_pric, @sel_cnt," +
                                        "@setl_time, @prcunt, @memo, @med_list_codg, @state, @InputJson,@create_time, @update_time);";
                                    cmd.Parameters.AddWithValue("@fixmedins_code", fsiRequest.fixmedins_code);
                                    cmd.Parameters.AddWithValue("@fixmedins_name", fsiRequest.fixmedins_name);
                                    cmd.Parameters.AddWithValue("@setl_id", fsiRequest.Input.selinfo.setl_id);
                                    cmd.Parameters.AddWithValue("@setl_flag", fsiRequest.Input.selinfo.setl_flag);
                                    cmd.Parameters.AddWithValue("@init_setl_id", fsiRequest.Input.selinfo.init_setl_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_id", fsiRequest.Input.selinfo.fixmedins_hilist_id);
                                    cmd.Parameters.AddWithValue("@fixmedins_hilist_name", fsiRequest.Input.selinfo.fixmedins_hilist_name);
                                    cmd.Parameters.AddWithValue("@med_type", fsiRequest.Input.selinfo.med_type);
                                    cmd.Parameters.AddWithValue("@mdtrt_sn", fsiRequest.Input.selinfo.mdtrt_sn);
                                    cmd.Parameters.AddWithValue("@psn_no", fsiRequest.Input.selinfo.psn_no);
                                    cmd.Parameters.AddWithValue("@psn_cert_type", fsiRequest.Input.selinfo.psn_cert_type);
                                    cmd.Parameters.AddWithValue("@psn_name", fsiRequest.Input.selinfo.psn_name);
                                    cmd.Parameters.AddWithValue("@bkkp_sn", fsiRequest.Input.selinfo.bkkp_sn);
                                    cmd.Parameters.AddWithValue("@trdn_flag", fsiRequest.Input.selinfo.trdn_flag);
                                    cmd.Parameters.AddWithValue("@Setl_pric", fsiRequest.Input.selinfo.Setl_pric);
                                    cmd.Parameters.AddWithValue("@sel_cnt", fsiRequest.Input.selinfo.sel_cnt);
                                    cmd.Parameters.AddWithValue("@setl_time", fsiRequest.Input.selinfo.setl_time);
                                    cmd.Parameters.AddWithValue("@prcunt", fsiRequest.Input.selinfo.prcunt);
                                    cmd.Parameters.AddWithValue("@memo", fsiRequest.Input.selinfo.memo);
                                    cmd.Parameters.AddWithValue("@med_list_codg", fsiRequest.Input.selinfo.med_list_codg);
                                    cmd.Parameters.AddWithValue("@state", 0);
                                    cmd.Parameters.AddWithValue("@InputJson", request.Content.ReadAsStringAsync().Result);
                                    cmd.Parameters.AddWithValue("@create_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    cmd.Parameters.AddWithValue("@update_time", dateTime.ToString("yyyy-MM-dd HH-mm-ss"));
                                    await cmd.ExecuteNonQueryAsync();
                                    cmd.Parameters.Clear();
                                }
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                            finally
                            {
                                if (conn.State == ConnectionState.Open)
                                {
                                    await conn.CloseAsync();
                                }
                            }
                        }
                    default:
                        throw new Exception($"[山东医保自定义接口]接口号{infno}未被定义，请检查入参或联系管理员！");
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}" 
                };
                return Json(FsiHeader);
            }
        }

    }
}
